/*
 * uart.h
 *
 * Created: 2013-11-5 7:34:22
 *  Author: alivehex
 */ 


#ifndef UART_H_
#define UART_H_

#include <avr/io.h>
#include "board.h"

#if (0)
uint32_t ubrr2Bdr(uint32_t ubrr) {
	return F_CPU / (8 * (ubrr + 1));
}

uint16_t bdr2Ubrr(uint32_t bdr) {
	return F_CPU / (8 * bdr) - 1;
}
#endif

#define UBRR2BDR(_UBRR) \
	(unsigned long)(F_CPU / (8 * (_UBRR + 1)))
	
#define BDR2UBRR(_BDR) \
	(F_CPU / (8 * _BDR) - 1) 

extern int uart1_open(unsigned long baudrate);
extern int uart1_close(void);
extern int uart1_putc(char c);
extern int uart1_getc(int timeout);
extern int uart1_puts(char *c);
extern void uart1_wait(void);
extern int kprintf(const char *str, ...);

int uartOpen(unsigned long bdr, int dataBits, int stopBits, int parity);
int uart1_open2(uint16_t ubrr, int dataBits, int stopBits, int parity);
void uartSetBaudrate(unsigned long baudrate);
void uartSetDataBit(int len) ;
void uartSetStopBit(int len);
void uartSetParity(int parity);


#endif /* UART_H_ */